{% extends "base_generic.html" %}
{% block script %}
<script type="text/javascript">
  function generateUrl(name) {
    var sanitizedName = name;
    sanitizedName = sanitizedName.replace(/ el /gi, ' ');
    sanitizedName = sanitizedName.replace(/ la /gi, ' ');
    sanitizedName = sanitizedName.replace(/ los /gi, ' ');
    sanitizedName = sanitizedName.replace(/ las /gi, ' ');
    sanitizedName = sanitizedName.replace(/ de /gi, ' ');
    sanitizedName = sanitizedName.replace(/ del /gi, ' ');
    sanitizedName = sanitizedName.replace(/ temporada /gi, ' ');
    sanitizedName = string_to_slug(sanitizedName);
    sanitizedName = sanitizedName.replace(/--/gi, '-');
    sanitizedName = sanitizedName.replace(/---/gi, '-');
    sanitizedName = sanitizedName.replace(/----/gi, '-');
    $("#slug").val(sanitizedName);
  }
  
  function loadCategories() {
    var directory = $("#directory").val();
    $.getJSON('/admin/loadCategories/' + directory, function(data) {
     var categories = '<option></option>';
     for (i=0; i < data['categories'].length; i++){
       categories += ("<option value='" + data['categories'][i].categoryId + "'>" + data['categories'][i].name + "</option>");
     }
     $("#category").html(categories);
    });
  }
  
  
  
  $(window).load(
    function() {
      $( "#firstPost" ).datepicker({ dateFormat: 'yy-mm-dd 00:00:00.000000' });
      
      var linkkey = "{{ link.key }}";
      
      if (linkkey == ""){
        loadCategories();
      }
      
    });
</script>
{% endblock %}
{% block content %}
        <h1>Link</h1>
        <form action="/admin/links/{{ link.key }}/save/" method="post">
        <div class="line">
          <div class="field">
            <label>From:</label>
            <select id="linker" name="linker">
              {% for project in projects %}
              <option value="{{ project.slug }}"{% ifequal link.linker project.slug %} selected="selected"{% endifequal %}>{{ project.slug }}</option>
              {% endfor %}
            </select>
          </div>
          <div class="field">
            <label>To:</label>
            <select id="linked" name="linked">
              {% for project in projects %}
              <option value="{{ project.slug }}"{% ifequal link.linked project.slug %} selected="selected"{% endifequal %}>{{ project.slug }}</option>
              {% endfor %}
            </select>
          </div>
        </div>
        <input type="submit" value="Guardar" id="save" name="save" name="save" /><br class="clear" />
      </form>
      <br class="clear" />

{% endblock %}
      